package com.erification.web.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.erification.web.dao.TrueNameDao;
import com.erification.web.model.TrueName;
import com.erification.web.service.TrueNameService;

@Service("trueNameService")
public class TrueNameServiceImpl implements TrueNameService {
	@Resource
	private TrueNameDao trueNameDao;
	@Override
	public void saveTrueName(TrueName trueName) {
		trueNameDao.save(trueName);
	}

	@Override
	public void ModifyFirstName(long user_id, TrueName tn, String firstName) {
		List<TrueName> list = trueNameDao.getAll(user_id);
		for(TrueName name : list){
			if( (name.getFirstName().equals(tn.getFirstName())) 
					&& (name.getLastName().equals(tn.getLastName()))){
				name.setFirstName(firstName);
				trueNameDao.update(name);
			}
		}
	}

	@Override
	public void ModifyLastName(long user_id,  TrueName tn, String lastName) {
		List<TrueName> list = trueNameDao.getAll(user_id);
		for(TrueName name : list){
			if( (name.getFirstName().equals(tn.getFirstName())) 
					&& (name.getLastName().equals(tn.getLastName()))){
				name.setLastName(lastName);
				trueNameDao.update(name);
			}
		}
	}

	@Override
	public void deleteTrueName(long id) {
		trueNameDao.delete(id);
	}

	@Override
	public List<TrueName> getAll(long user_id) {
		return trueNameDao.getAll(user_id);
	}

	@Override
	public TrueName get(long id) {
		return trueNameDao.getTrueNameById(id);
	}

}
